package com.itshizhan.designpattern.iterator;

/**
 * 具体的集合 Concrete Aggregate
 * 负责实现 Aggregate 集合
 * 会创建出具体的Iterator角色，即 Concrete Iterator
 *
 */
public class BookShelf implements Aggregate{
    private Book[] books;
    private int last = 0;

    public BookShelf(int maxsize) {
        this.books = new Book[maxsize];
    }
    public Book getBookAt(int index){
        return books[index];
    }
    public void appendBook(Book book){
        this.books[last] = book;
        last++;
    }
    public int getLength(){
        return last;
    }


    @Override
    public Iterator iterator() {
        return new BookShelfIterator(this);
    }
}
